#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
using ll = long long;
// 使用 线性 dp

const int N = 2e5 + 10;
ll dp[N];

int main(){

    int n; cin >> n;
    ll ret = INT_MIN;
    for (int i = 1; i <= n; i++){
        ll x; scanf("%lld", &x);
        dp[i] = max(dp[i - 1], static_cast<ll>(0)) + x;
        ret = max(ret, dp[i]);
    }
    cout << ret << endl;
    return 0;
}